package cn.tx.controller;

import java.util.List;
import java.util.Set;

import cn.tx.model.ProductType;
import cn.tx.model.Supplier;
import cn.tx.query.SupplierQuery;
import cn.tx.service.SupplierService;
import cn.tx.util.JSONWriter;
import cn.tx.util.Page;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

public class SupplierAction extends BaseAction implements ModelDriven<Supplier>{
	
	private Supplier supplier = new Supplier();
	
	private SupplierService supplierService;
	
	
	
	
	public Supplier getSupplier() {
		return supplier;
	}

	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	/**
	 * 查询对象
	 */
	private SupplierQuery erpQuery = new SupplierQuery();
	
	
	public SupplierService getSupplierService() {
		return supplierService;
	}

	public void setSupplierService(SupplierService supplierService) {
		this.supplierService = supplierService;
	}
	

	public SupplierQuery getErpQuery() {
		return erpQuery;
	}

	public void setErpQuery(SupplierQuery erpQuery) {
		this.erpQuery = erpQuery;
	}

	/**
	 * 查询员工的列表
	 * @return
	 */
	public String supplier_list(){
		//获得action的容器
		ActionContext context = ActionContext.getContext();
		Page page = supplierService.selectObjectByConditionPage(erpQuery, exclude);
		context.put("page", page);
		
		return SUCCESS;
	}
	
	/**
	 * 跳转到添加页面
	 * @return
	 */
	public String supplier_input(){
		
		return SUCCESS;
	}
	/**
	 * 跳转到修改页面
	 * @return
	 */
	public String supplier_preupdate(){
		supplier = supplierService.getObjectById(supplier.getSupplierId());
		return SUCCESS;
	}
	/**
	 * 根据供应商查询下面的所有商品类别
	 */
	/*public void supplier_getSupplierById(){
		supplier = supplierService.getObjectById(supplier.getSupplierId());
		Set<ProductType> pts = supplier.getPts();
		
		JSONWriter.writeJSONArray(pts, response, new String[]{"supplier","pset"});
	}*/
	/**
	 * 保存
	 * @return
	 */
	public String supplier_save(){
		supplierService.save(supplier);
		return TOLIST;
	}
	/**
	 * 修改
	 * @return
	 */
	public String supplier_update(){
		supplierService.update(supplier);
		return TOLIST;
	}
	/**
	 * 修改
	 * @return
	 */
	public String supplier_delete(){
		supplier = supplierService.getObjectById(supplier.getSupplierId());
		supplierService.delete(supplier);
		return TOLIST;
	}

	@Override
	public Supplier getModel() {
		return supplier;
	}
	
	
	
	

}
